import 'package:get/get.dart';
import 'package:getx_learn/app/modules/getx_controller_demo/modules/getconnect_page/providers/iweather_provider.dart';

class StatemixinPageController extends GetxController with StateMixin<String>{
  //TODO: Implement StatemixinPageController
  late IWeatherProvider _weatherProvider;

  var isSuccess = true;

  Future<void> fetchWeatherInfo() async {
    final String response = await _weatherProvider.getWeatherInfo();

    /// 混入 StateMixin<String> 之后，就可以调用change了
    if (isSuccess){
      change(response, status: RxStatus.success());
    } else {
      change(null, status: RxStatus.error("失败"));
    }


    isSuccess = !isSuccess;
  }

  Future<void> fetchAppUpdate() async {

    final String response = await _weatherProvider.fetchAppUpdate();
    /// 混入 StateMixin<String> 之后，就可以调用change了
    if (isSuccess){
      change(response, status: RxStatus.success());
    } else {
      change(null, status: RxStatus.error("失败"));
    }


    isSuccess = !isSuccess;
  }

  @override
  void onInit() {
    super.onInit();
    _weatherProvider = Get.find();
  }

  @override
  void onReady() {
    super.onReady();
  }

  @override
  void onClose() {
    super.onClose();
  }

}
